<!DOCTYPE html>
<html lang="en">
<head>
    <title>大客户经理周拜访计划</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=e9c5bb62">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=66b457d6">
    <style>
        table input {
            border: none;
            width: 100%;
        }
    </style>
</head>
<body>
<section class="content" id="app" v-cloak>
    <table class="table  table-bordered text-center" id="week">
        <tr class="td-module">
            <td>日期</td>
            <td>客户名称</td>
            <td>上次拜访时间</td>
            <td>客户地点</td>
            <td>客户行业</td>
            <td>意向设备</td>
            <td>备注</td>

        </tr>
        <tr v-for="(item,i) in list">
            <td :rowspan="item.weekNamespan" :class="{hidden: item.weekNamedis}">
                {{item.weekName}}<br>({{item.weekTime}})
            </td>
            <td style="width: 120px;">
                <input style="text-align: center" class="txtParent" type="text" v-model="item.customerName" v-if="new Date().getDay()==0">
                <span v-else>{{item.customerName}}</span>
            </td>
            <td style="width: 120px;">
                <input style="text-align: center" type="text" v-model="item.lastVisitTime" @focus="showDatePicker($event,i)" v-if="new Date().getDay()==0">
                <span v-else>{{item.lastVisitTime}}</span>
            </td>
            <td style="width: 120px;">
                <input style="text-align: center" type="text" v-model="item.customerAddress" v-if="new Date().getDay()==0">
                <span v-else>{{item.customerAddress}}</span>
            </td>
            <td style="width: 120px;">
                <input type="text" v-model="item.customerIndustry" v-if="new Date().getDay()==0">
                <span v-else>{{item.customerIndustry}}</span>
            </td>
            <td style="width: 120px;">
                <input style="text-align: center" type="text" v-model="item.intentionDevice" v-if="new Date().getDay()==0">
                <span v-else>{{item.intentionDevice}}</span>
            </td>
            <td >
                <input type="text" v-model="item.remake" v-if="new Date().getDay()==0">
                <span v-else>{{item.remake}}</span>
            </td>
        </tr>
    </table>
    <input type="button" id="save" class="saveBtn btn oaBtn" @click="save" value="保存"
           style="margin-left: 560px ;margin-top: 5px">
    <input type="button" id="add" class="saveBtn btn oaBtn" @click="add" value="提交"
           style="margin-left: 560px ;margin-top: 5px;">


    <!-- /.box-body -->
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=0b5caf39"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=0c4d95a9"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript">
    console.log(urlConfig);
    var app = new Vue({
        el: '#app',
        data: {
            list: [],
            week: []
        },
        methods: {
            onfocus1: function (i) {
                var that = this;
                that.currentfocus = i;
            },
            tablesMergeCell: function (list) {
                for (field in list[0]) {
                    var k = 0;
                    while (k < list.length) {
                        list[k][field + 'span'] = 1;
                        list[k][field + 'dis'] = false;
                        for (var i = k + 1; i <= list.length - 1; i++) {
                            if (list[k][field] == list[i][field] && list[k][field] != '') {
                                list[k][field + 'span']++;
                                list[k][field + 'dis'] = false;
                                list[i][field + 'span'] = 1;
                                list[i][field + 'dis'] = true;
                            } else {
                                break;
                            }
                        }
                        k = i;
                    }
                }
                return list;
            },
            getWeek: function () {
                var that = this;
                const week = [];
                for (var i = 0; i < 6; i++) {
                    var Stamp = new Date();
                    var num =1+i;
                    Stamp.setDate(Stamp.getDate() + num);
                    var mvar = '';
                    if ((Stamp.getMonth() + 1) > 10) {
                        mvar = (Stamp.getMonth() + 1);
                    } else {
                        mvar = '0' + (Stamp.getMonth() + 1);
                    }
                    var dvar = '';
                    if (Stamp.getDate() < 10) {
                        dvar = '0' + Stamp.getDate();
                    } else {
                        dvar = Stamp.getDate() + '';
                    }
                    if ((Stamp.getMonth() + 1) > 10) {
                    } else {
                    }
                    week[i] = Stamp.getFullYear() + '-' + mvar + '-' + dvar;
                    console.log(week[i]);
                }
                that.week = week;
            },
            initData: function () {
                var that = this;
                that.getWeek();
                var list = [
                    {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[0],
                        "weekName": "星期一"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[0],
                        "weekName": "星期一"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[0],
                        "weekName": "星期一"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[1],
                        "weekName": "星期二"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[1],
                        "weekName": "星期二"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[1],
                        "weekName": "星期二"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[2],
                        "weekName": "星期三"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[2],
                        "weekName": "星期三"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[2],
                        "weekName": "星期三"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[3],
                        "weekName": "星期四"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[3],
                        "weekName": "星期四"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[3],
                        "weekName": "星期四"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[4],
                        "weekName": "星期五"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[4],
                        "weekName": "星期五"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[4],
                        "weekName": "星期五"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[5],
                        "weekName": "星期六"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[5],
                        "weekName": "星期六"
                    }, {
                        "createTime": "",
                        "createUserId": getCurrentUser().id,
                        "customerAddress": "",
                        "customerIndustry": "",
                        "customerName": "",
                        "id": 0,
                        "intentionDevice": "",
                        "lastVisitTime": "",
                        "remake": "",
                        "weekTime": that.week[5],
                        "weekName": "星期六"
                    }

                ]
                that.list = this.tablesMergeCell(list);

            },
            refreshWeek: function () {
                var that = this;
                $.wyui.postMethod('/weekPlan/getWeek.json', {createUserId: getCurrentUser().id,}, function (r) {
                    console.log(r);
                    that.list = r.records;
                    this.list = that.tablesMergeCell(that.list);
                })
            },
            del: function (weekId) {
                if (confirm('确认要删除吗？')) {
                    var that = this;
                    $.wyui.postMethod('/weekPlan/removeById.json', {id: weekId}, function (r) {
                        console.log(r);
                        if (r.records == "删除成功") {
                            alert("删除成功");
                            that.refreshWeek();
                        }

                    });
                }
            },
            add: function () {
                var newList = [];
                var that = this;
                for (var i = 0; i < this.list.length; i++) {
                    console.log(this.list[i].customerName)
                    if (this.list[i].customerName != "") {
                        if (this.list[i].customerAddress == "") {
                            alert("请填写客户地址！");
                            return false;
                        }
                        if (this.list[i].customerIndustry == "") {
                            alert("请填写客户行业！");
                            return false;
                        }
                        if (this.list[i].intentionDevice == "") {
                            alert("请填写意向设备！");
                            return false;
                        }
                        newList.push(this.list[i]);
                    }
                }
                if (newList.length > 0) {
                    $.wyui.postMethod('/weekPlan/add.json', trimRN(that.list), function (r) {
                        console.log(r);
                        alert("提交成功！");
                        that.refreshWeek();
                        $("#add").hide();
                        $("#save").show();
                    })
                } else {
                    alert("请添加至少一条记录！")
                }

            },
            showDatePicker: function (e, index) {
                var that = this;
                console.log(index)
                WdatePicker({
                    onpicked: function (dp) {
                        console.log(that.list[index].customerName)
                        that.list[index].lastVisitTime = dp.cal.getNewDateStr();
                        console.log(that.list[index].customerName)
                        return true;
                    }
                });
                $(e.target).blur();
            },
            getNowFormatDate: function () {
                var that=this;
                var date = new Date();
                var seperator1 = "-";
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var strDate = date.getDate();
                if (month >= 1 && month <= 9) {
                    month = "0" + month;
                }
                if (strDate >= 0 && strDate <= 9) {
                    strDate = "0" + strDate;
                }
                var currentdate = year + seperator1 + month + seperator1 + strDate;
                return currentdate;
            },
            save: function () {
                var newList = [];
                var that = this;
                for (var i = 0; i < this.list.length; i++) {
                    console.log(this.list[i].customerName)
                    if (this.list[i].customerName != "") {
                        if (this.list[i].customerAddress == "") {
                            alert("请填写客户地址！");
                            return false;
                        }
                        if (this.list[i].customerIndustry == "") {
                            alert("请填写客户行业！");
                            return false;
                        }
                        if (this.list[i].intentionDevice == "") {
                            alert("请填写意向设备！");
                            return false;
                        }
                        newList.push(this.list[i]);
                    }

                }
                if (newList.length > 0) {
                    $.wyui.postMethod('/weekPlan/update.json',  trimRN(that.list), function (r) {
                        console.log(r);
                        if (r.records == "修改成功") {
                            alert("保存成功");
                            that.refreshWeek();
                        }
                    })
                } else {
                    alert("请添加至少一条记录！")
                }


            }
        },
        mounted: function () {
            var dt = new Date();
            var that = this;
            console.log(dt.getDay())
            if(dt.getDay() != 0){alert("请于周日填写下周 周拜访计划！！")}
            if (dt.getDay() == 0) {
                $.wyui.postMethod('/weekPlan/getWeek.json', {
                    createUserId: getCurrentUser().id,
                    reportDate: that.getNowFormatDate(),
                }, function (r) {
                    if (r.records.length > 0) {
                        that.refreshWeek();
                        $("#add").hide();
                    } else {
                        that.initData();
                        $("#save").hide();
                    }
                })
            } else {
                $("#save").hide();
                $("#add").hide();
                that.refreshWeek();

            }
        }
    });
    function renderLines(el, lineIndex) {

        $(".txtParent").eq(lineIndex).autoComplete({
            url: server.ip + "/weekPlan/getNameAndTel.json",
            render: function (r, panel) {
                for (var i = 0; i < r.length; i++) {
                    $("<li></li>").data("autoComplete",
                        r[i]).html("<a>" + r[i].customerName + "&nbsp;&nbsp;&nbsp;" +
                        "(" + "&nbsp;" + r[i].customerTel + ") " + "</a>")
                        .appendTo(panel);
                }
            },
            selected: function (r) {
                app.list[app.currentfocus].customerName = r.customerName;
                app.list[app.currentfocus].customerAddress = r.customerAddress;
                app.list[app.currentfocus].lastVisitTime = r.lastVisitTime;
                app.list[app.currentfocus].customerIndustry = r.customerIndustry;
                app.list[app.currentfocus].intentionDevice = r.intentionDevice;
                return false;
            },
            extraParams: {createUserId: getCurrentUser().id},
            height: 210,
            width: 300
        });
    }

    Vue.directive('line-inserted', {
        inserted: function (el, binding) {
            console.log(el);
            var lineIndex = binding.value;
            renderLines(el, lineIndex);
        }
    });
</script>

</body>
</html>